package references

import "jvmgo/ch06/instructions/base"
import "jvmgo/ch06/rtda"
import "jvmgo/ch06/rtda/heap"

// 创建类
type NEW struct {
    base.Index16Instruction
}

func (self *NEW) Execute(frame *rtda.Frame) {
    cp := frame.Method().Class().ConstantPool()
    classRef := cp.GetConstant(self.Index).(*heap.ClassRef)
    class := classRef.ResolvedClass()
    // todo: 初始化类

    if class.IsInterface() || class.IsAbstract() {
        panic("java.lang.InstantiationError")
    }

    ref := class.NewObject()
    frame.OperandStack().PushRef(ref)
}
